--------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  C:/yourdirectory/logs/coalstocks.log
  log type:  text
 opened on:  18 Jun 2016, 19:02:06

. 
. set more off

. set matsize 1000

. 
. 
. *_______________________________________________________________________________
. 
. 
. /* Get electricity sector and total coal stocks (thousand short tons)
>    All values are for the end of the indicated period                           */
. use "`dir_input'/eia_coalstocks.dta", clear

. 
. tsset Counter
        time variable:  Counter, 1 to 488
                delta:  1 unit

. 
. gen delta_electr = Electricity-L.Electricity
(2 missing values generated)

. gen delta_total = Total-L.Total
(2 missing values generated)

. gen pct_electr = ln(Electricity/L.Electricity)
(2 missing values generated)

. gen pct_total = ln(Total/L.Total)
(2 missing values generated)

. 
. gen eventmonth = 0

. replace eventmonth = 1 if (Year==2010 & Month==4)
(1 real change made)

. 
. * Electricity sector's stock
. xi: ivreg2 pct_electr eventmonth, kernel(bartlett) bw(auto) small       

OLS estimation
--------------

Estimates efficient for homoskedasticity only
Statistics robust to autocorrelation
  kernel=Bartlett; bandwidth=    29
  Automatic bw selection according to Newey-West (1994)
  time variable (t):  Counter

                                                      Number of obs =      487
                                                      F(  1,   485) =     1.69
                                                      Prob > F      =   0.1939
Total (centered) SS     =  1.098487707                Centered R2   =   0.0035
Total (uncentered) SS   =  1.098993616                Uncentered R2 =   0.0039
Residual SS             =  1.094663929                Root MSE      =   .04751

------------------------------------------------------------------------------
  pct_electr |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
  eventmonth |   .0619003   .0475771     1.30   0.194    -.0315824     .155383
       _cons |   .0008921   .0016931     0.53   0.598    -.0024346    .0042188
------------------------------------------------------------------------------
Included instruments: eventmonth
------------------------------------------------------------------------------

. estimates store nofe

. xi: ivreg2 pct_electr eventmonth i.Month, kernel(bartlett) bw(auto) small       
i.Month           _IMonth_1-12        (naturally coded; _IMonth_1 omitted)

OLS estimation
--------------

Estimates efficient for homoskedasticity only
Statistics robust to autocorrelation
  kernel=Bartlett; bandwidth=    19
  Automatic bw selection according to Newey-West (1994)
  time variable (t):  Counter

                                                      Number of obs =      487
                                                      F( 12,   474) =    29.95
                                                      Prob > F      =   0.0000
Total (centered) SS     =  1.098487707                Centered R2   =   0.5154
Total (uncentered) SS   =  1.098993616                Uncentered R2 =   0.5156
Residual SS             =  .5323745931                Root MSE      =   .03351

------------------------------------------------------------------------------
  pct_electr |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
  eventmonth |   .0178993   .0338903     0.53   0.598    -.0486944    .0844931
   _IMonth_2 |   .0333444   .0052094     6.40   0.000     .0231079    .0435808
   _IMonth_3 |   .0712021   .0071553     9.95   0.000     .0571422    .0852621
   _IMonth_4 |   .0853074    .008127    10.50   0.000     .0693381    .1012768
   _IMonth_5 |   .0730023   .0084309     8.66   0.000     .0564357    .0895688
   _IMonth_6 |   .0307367   .0083581     3.68   0.000     .0143131    .0471603
   _IMonth_7 |  -.0246331   .0082171    -3.00   0.003    -.0407796   -.0084866
   _IMonth_8 |   .0148648   .0083541     1.78   0.076    -.0015509    .0312806
   _IMonth_9 |   .0546862    .008479     6.45   0.000     .0380252    .0713473
  _IMonth_10 |    .082509   .0081332    10.14   0.000     .0665274    .0984906
  _IMonth_11 |    .062613    .007207     8.69   0.000     .0484515    .0767746
  _IMonth_12 |    .013278   .0052756     2.52   0.012     .0029116    .0236444
       _cons |  -.0404144   .0055347    -7.30   0.000      -.05129   -.0295388
------------------------------------------------------------------------------
Included instruments: eventmonth _IMonth_2 _IMonth_3 _IMonth_4 _IMonth_5
                      _IMonth_6 _IMonth_7 _IMonth_8 _IMonth_9 _IMonth_10
                      _IMonth_11 _IMonth_12
------------------------------------------------------------------------------

. estimates store monthfe

. xi: ivreg2 pct_electr eventmonth i.Month i.Year, kernel(bartlett) bw(auto) small        
i.Month           _IMonth_1-12        (naturally coded; _IMonth_1 omitted)
i.Year            _IYear_1973-2013    (naturally coded; _IYear_1973 omitted)

OLS estimation
--------------

Estimates efficient for homoskedasticity only
Statistics robust to autocorrelation
  kernel=Bartlett; bandwidth=    29
  Automatic bw selection according to Newey-West (1994)
  time variable (t):  Counter

                                                      Number of obs =      487
                                                      F( 52,   434) =     7.81
                                                      Prob > F      =   0.0000
Total (centered) SS     =  1.098487707                Centered R2   =   0.5877
Total (uncentered) SS   =  1.098993616                Uncentered R2 =   0.5879
Residual SS             =  .4528650077                Root MSE      =    .0323

------------------------------------------------------------------------------
  pct_electr |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
  eventmonth |    .027942   .0339649     0.82   0.411    -.0388142    .0946982
   _IMonth_2 |   .0336537   .0054471     6.18   0.000     .0229477    .0443598
   _IMonth_3 |   .0715115   .0076566     9.34   0.000     .0564629    .0865601
   _IMonth_4 |   .0853718   .0088393     9.66   0.000     .0679987    .1027449
   _IMonth_5 |   .0733116   .0091844     7.98   0.000     .0552602     .091363
   _IMonth_6 |   .0310461   .0091102     3.41   0.001     .0131404    .0489517
   _IMonth_7 |  -.0243238   .0089028    -2.73   0.007    -.0418217   -.0068258
   _IMonth_8 |   .0151742   .0091041     1.67   0.096    -.0027194    .0330677
   _IMonth_9 |    .054582   .0092351     5.91   0.000     .0364309     .072733
  _IMonth_10 |   .0824047    .008855     9.31   0.000     .0650006    .0998088
  _IMonth_11 |   .0625088   .0077154     8.10   0.000     .0473447    .0776729
  _IMonth_12 |   .0131738   .0055194     2.39   0.017     .0023257    .0240218
 _IYear_1974 |   .0081812   .0137926     0.59   0.553    -.0189274    .0352897
 _IYear_1975 |   .0350696    .012369     2.84   0.005      .010759    .0593801
 _IYear_1976 |   .0164666   .0121274     1.36   0.175    -.0073692    .0403024
 _IYear_1977 |   .0220711   .0121449     1.82   0.070    -.0017991    .0459412
 _IYear_1978 |    .008378   .0121449     0.69   0.491    -.0154921    .0322482
 _IYear_1979 |   .0298621   .0121449     2.46   0.014      .005992    .0537323
 _IYear_1980 |   .0229088   .0121449     1.89   0.060    -.0009614    .0467789
 _IYear_1981 |   .0048731   .0121449     0.40   0.688    -.0189971    .0287432
 _IYear_1982 |   .0173925   .0121449     1.43   0.153    -.0064777    .0412626
 _IYear_1983 |  -.0011004   .0121449    -0.09   0.928    -.0249706    .0227697
 _IYear_1984 |   .0235763   .0121449     1.94   0.053    -.0002939    .0474464
 _IYear_1985 |  -.0000356   .0121449    -0.00   0.998    -.0239057    .0238345
 _IYear_1986 |   .0144069   .0121449     1.19   0.236    -.0094633     .038277
 _IYear_1987 |    .016069   .0121449     1.32   0.186    -.0078012    .0399391
 _IYear_1988 |  -.0012211   .0121449    -0.10   0.920    -.0250912     .022649
 _IYear_1989 |   .0052749   .0121449     0.43   0.664    -.0185952     .029145
 _IYear_1990 |   .0231701   .0121449     1.91   0.057       -.0007    .0470402
 _IYear_1991 |   .0124702   .0121449     1.03   0.305       -.0114    .0363403
 _IYear_1992 |   .0095609   .0121449     0.79   0.432    -.0143092    .0334311
 _IYear_1993 |  -.0155376   .0121449    -1.28   0.201    -.0394077    .0083325
 _IYear_1994 |   .0224606   .0121449     1.85   0.065    -.0014095    .0463308
 _IYear_1995 |   .0111724   .0121449     0.92   0.358    -.0126977    .0350426
 _IYear_1996 |   .0034755   .0121449     0.29   0.775    -.0203947    .0273456
 _IYear_1997 |  -.0007957   .0121449    -0.07   0.948    -.0246658    .0230745
 _IYear_1998 |   .0280877   .0121449     2.31   0.021     .0042176    .0519579
 _IYear_1999 |   .0250102   .0121449     2.06   0.040       .00114    .0488803
 _IYear_2000 |  -.0155349   .0121449    -1.28   0.202    -.0394051    .0083352
 _IYear_2001 |   .0368102   .0121449     3.03   0.003       .01294    .0606803
 _IYear_2002 |   .0134765   .0121449     1.11   0.268    -.0103936    .0373466
 _IYear_2003 |   -.001216   .0121449    -0.10   0.920    -.0250861    .0226542
 _IYear_2004 |   .0006674   .0121449     0.05   0.956    -.0232028    .0245375
 _IYear_2005 |   .0071244   .0121449     0.59   0.558    -.0167458    .0309945
 _IYear_2006 |    .039232   .0121449     3.23   0.001     .0153618    .0631021
 _IYear_2007 |   .0174154   .0121449     1.43   0.152    -.0064548    .0412855
 _IYear_2008 |   .0170882    .012145     1.41   0.160    -.0067821    .0409586
 _IYear_2009 |   .0248257   .0121455     2.04   0.042     .0009544     .048697
 _IYear_2010 |   .0025755   .0124083     0.21   0.836    -.0218124    .0269634
 _IYear_2011 |    .010348   .0121442     0.85   0.395    -.0135208    .0342168
 _IYear_2012 |   .0174123   .0121429     1.43   0.152    -.0064538    .0412785
 _IYear_2013 |  -.0041703   .0154108    -0.27   0.787    -.0344594    .0261187
       _cons |  -.0530969   .0105189    -5.05   0.000    -.0737712   -.0324226
------------------------------------------------------------------------------
Included instruments: eventmonth _IMonth_2 _IMonth_3 _IMonth_4 _IMonth_5
                      _IMonth_6 _IMonth_7 _IMonth_8 _IMonth_9 _IMonth_10
                      _IMonth_11 _IMonth_12 _IYear_1974 _IYear_1975 _IYear_1976
                      _IYear_1977 _IYear_1978 _IYear_1979 _IYear_1980
                      _IYear_1981 _IYear_1982 _IYear_1983 _IYear_1984
                      _IYear_1985 _IYear_1986 _IYear_1987 _IYear_1988
                      _IYear_1989 _IYear_1990 _IYear_1991 _IYear_1992
                      _IYear_1993 _IYear_1994 _IYear_1995 _IYear_1996
                      _IYear_1997 _IYear_1998 _IYear_1999 _IYear_2000
                      _IYear_2001 _IYear_2002 _IYear_2003 _IYear_2004
                      _IYear_2005 _IYear_2006 _IYear_2007 _IYear_2008
                      _IYear_2009 _IYear_2010 _IYear_2011 _IYear_2012
                      _IYear_2013
------------------------------------------------------------------------------

. estimates store yearfe

. 
. 
. * Total U.S. stock - Not doing this because data other than electric power sector are imputed from quarterly data by usi
> ng 1/3 of the quarterly change
. /*
> xi: ivreg2 pct_total eventmonth, kernel(bartlett) bw(auto) small        
> xi: ivreg2 pct_total eventmonth i.Month, kernel(bartlett) bw(auto) small        
> xi: ivreg2 pct_total eventmonth i.Month i.Year, kernel(bartlett) bw(auto) small 
> */
. 
. local specif_list "nofe monthfe yearfe"

. 
. foreach specif of local specif_list{
  2.         /* obtain residuals so can do SQ test and normality tests */
.         estimates restore `specif'
  3.         predict resid_`specif', residual
  4.         *egen std_resid_`specif'  = std(resid_`specif')
. 
.         * save residuals for taking into Excel
.         save "`dir_output'/temp_results.dta", replace
  5.         drop if eventmonth==1
  6.         keep resid_*
  7.         *xpose, clear varname
.         save "`dir_output'/resids.dta", replace
  8.         use "`dir_output'/temp_results.dta"  /* get all variables back */       
  9.         
.         drop if eventmonth==1
 10.         * Shapiro-Wilk test for normality
.         swilk resid_`specif'
 11.         * Jarque-Bera test for normality
.         jb6 resid_`specif'
 12.         use "`dir_output'/temp_results.dta", clear  /* get all variables back */        
 13. }
(results nofe are active now)
(2 missing values generated)
(note: file C:/yourdirectory/output/coalstocks/temp_results.dta not found)
file C:/yourdirectory/output/coalstocks/temp_results.dta saved
(1 observation deleted)
(note: file C:/yourdirectory/output/coalstocks/resids.dta not found)
file C:/yourdirectory/output/coalstocks/resids.dta saved
(1 observation deleted)

                   Shapiro-Wilk W test for normal data

    Variable |    Obs       W           V         z       Prob>z
-------------+--------------------------------------------------
  resid_nofe |    486    0.97208      9.156     5.316    0.00000
Jarque-Bera normality test:   96.4 Chi(2)  1.2e-21
Jarque-Bera test for Ho: normality: (resid_nofe)
(results monthfe are active now)
(2 missing values generated)
file C:/yourdirectory/output/coalstocks/temp_results.dta saved
(1 observation deleted)
file C:/yourdirectory/output/coalstocks/resids.dta saved
(1 observation deleted)

                   Shapiro-Wilk W test for normal data

    Variable |    Obs       W           V         z       Prob>z
-------------+--------------------------------------------------
resid_mont~e |    486    0.92132     25.799     7.803    0.00000
Jarque-Bera normality test:   1027 Chi(2)  8.e-224
Jarque-Bera test for Ho: normality: (resid_monthfe)
(results yearfe are active now)
(2 missing values generated)
file C:/yourdirectory/output/coalstocks/temp_results.dta saved
(1 observation deleted)
file C:/yourdirectory/output/coalstocks/resids.dta saved
(1 observation deleted)

                   Shapiro-Wilk W test for normal data

    Variable |    Obs       W           V         z       Prob>z
-------------+--------------------------------------------------
resid_yearfe |    486    0.89750     33.610     8.438    0.00000
Jarque-Bera normality test:   1700 Chi(2)      0
Jarque-Bera test for Ho: normality: (resid_yearfe)

. 
. drop if eventmonth==1
(1 observation deleted)

. 
. 
. /* Plot density of residuals and original variable*/
. kdensity resid_yearfe, generate(x_resid_base y_resid_base) nograph                      

. keep x_* y_*

. save "`dir_output'/kdensity_base.dta", replace
(note: file C:/yourdirectory/output/coalstocks/kdensity_base.dta not found)
file C:/yourdirectory/output/coalstocks/kdensity_base.dta saved

. use "`dir_output'/temp_results.dta"  /* get all variables back */       

. drop if eventmonth==1
(1 observation deleted)

. kdensity pct_electr, generate(x_var y_var) nograph                      

. keep x_* y_*

. save "`dir_output'/kdensity_originalvar.dta", replace
(note: file C:/yourdirectory/output/coalstocks/kdensity_originalvar.dta not found)
file C:/yourdirectory/output/coalstocks/kdensity_originalvar.dta saved

. use "`dir_output'/temp_results.dta"  /* get all variables back */       

. 
. log close
      name:  <unnamed>
       log:  C:/yourdirectory/logs/coalstocks.log
  log type:  text
 closed on:  18 Jun 2016, 19:02:09
--------------------------------------------------------------------------------------------------------------------------
